﻿using System;

namespace Fluent
{
    public class IFrame : IDisposable
    {
        public Browser Browser { get; private set; }
        public string Name { get; private set; }

        public IFrame(Browser browser, string nameOrID)
        {
            this.Browser = browser;
            this.Name = nameOrID;
        }

        public static IFrame Using(Browser browser, string nameOrID)
        {
            return new IFrame(browser, nameOrID).Using();
        }

        public IFrame Using()
        {
            Browser.GetDriver().SwitchTo().Frame(this.Name);
            return this;
        }

        public void Dispose()
        {
            Browser.GetDriver().SwitchTo().DefaultContent();
        }
    }

    public class IFrame<TPage, TContainerPage> : IFrame
        where TPage : WebPageBase
        where TContainerPage : WebPageBase
    {
        public TContainerPage ContainerPage { get; private set; }

        public IFrame(Browser browser, string nameOrID, TContainerPage containerPage)
            : base(browser, nameOrID)
        {
            this.ContainerPage = containerPage;
        }

        public TContainerPage Using()
        {
            base.Using();

            return this.ContainerPage;
        }
    }
}